﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Obligatorio2013.Modelo;

namespace Obligatorio2013
{
    public partial class UserForm : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if ((bool)Session["logged"] == true)
            {
                if (!Page.IsPostBack)
                {
                    if (Session["controller"] == null)
                    {
                        Session["controller"] = Sistema.Instance;
                    }
                }
            }
            else
            {
                Response.Redirect("~/Pages/Private/LoginForm.aspx");
            }
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {

            Response.Redirect("~/Pages/UserList.aspx", true);
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            Sistema system = Sistema.Instance;
            bool ret = system.validateUserInfo(this.txtName.Text, this.txtLastName.Text, this.txtAddress.Text, this.txtLocation.Text, this.txtPhone.Text, this.txtEmail.Text,
                this.txtUser.Text, this.txtPass.Text);

            if (ret)
            {
                system.saveUser(this.txtName.Text, this.txtLastName.Text, this.txtAddress.Text, this.txtLocation.Text, this.txtPhone.Text, this.txtEmail.Text,
                this.txtUser.Text, this.txtPass.Text);
            }

        }

        private void cleanForm()
        {
            this.txtName.Text = "";
            this.txtLastName.Text = "";
            this.txtAddress.Text = "";
            this.txtLocation.Text = "";
            this.txtPhone.Text = "";
            this.txtEmail.Text = "";
            this.txtUser.Text = "";
            this.txtPass.Text = "";
        }


    }
}